<?php
    //Installation opcodes defines
	define( "CONST_TEST_CONNECTION_OPCODE" , 0 );
	define( "CONST_INSTALL_OPCODE" , 1 );
	
	//CMS tables defines
	define( "CONST_USERS_TABLE" , "users" );
	define( "CONST_USER_GROUPS_TABLE" , "users_groups" );
	define( "CONST_USER_PERMISSIONS_TABLE" , "users_permissions" );
	
	define( "CONST_CONTENT_TYPES_TABLE" , "content_types" );
	define( "CONST_FIELD_TYPES_TABLE" , "field_types" );
	
	//Configuration file
	
	define( "CONST_CONFIG_FILE" , "../common/config.include" );

	
	if( isset( $_POST["jsonCall"] ) ){		
						
		$jsonCall = json_decode($_POST["jsonCall"] , true );
		
		$jsonError = null;

		switch(json_last_error()){
			
			case JSON_ERROR_DEPTH:
		
				$jsonError = 'Maximum stack depth exceeded';
		
			break;
			case JSON_ERROR_CTRL_CHAR:
		
				$jsonError = 'Unexpected control character found';
		
			break;
			case JSON_ERROR_SYNTAX:
		
				$jsonError = 'Syntax error, malformed JSON';
		
			break;
			case JSON_ERROR_NONE:
		
				$jsonError = null;
		
			break;
			
		}
		
		if( $jsonError !== null ){
			
			$result = array();
			
			$result["state"] = "KO";
			
			$result["errMsg"] = $jsonError."\n json: {$_POST["jsonCall"]}";
						
			echo json_encode( $result );
			
			exit;
					
		}
		
		switch( $jsonCall["opcode"] ){
			
			case CONST_TEST_CONNECTION_OPCODE :
			
				testConnection( $jsonCall["params"] );
			
				break;
				
			case CONST_INSTALL_OPCODE :
			
				install( $jsonCall["params"] );
			
				break;
		
		}
		

	}
	
	function testConnection( $connParams ){
		
		foreach( $connParams as $key => $value ){
		
			$connParams[$key] = trim( $value );
			
		}
		
				
		$result = array();
		
		if( !isset( $connParams["host"] ) or $connParams["host"] == "" ){
			
			$result["state"] = "KO";
			
			$result["errMsg"] = "DB host cannot be null";
			
			echo json_encode( $result );
	
			exit;
		
		}
		
		if( !isset( $connParams["port"] ) or $connParams["port"] == "" ){
			
			$result["state"] = "KO";
			
			$result["errMsg"] = "DB port cannot be null";
			
			echo json_encode( $result );
	
			exit;
		
		}
		
		if( !isset( $connParams["dbAdmin"] ) or $connParams["dbAdmin"] == "" ){
			
			$result["state"] = "KO";
			
			$result["errMsg"] = "A name for the CMS administartor must be specified";
			
			echo json_encode( $result );
	
			exit;
		
		}
		
		if( !isset( $connParams["dbAdminPwd"] ) or $connParams["dbAdminPwd"] == "" ){
			
			$result["state"] = "KO";
			
			$result["errMsg"] = "A password for the CMS administartor must be specified";
			
			echo json_encode( $result );
	
			exit;
		
		}
		
		if( $conn = @mysql_connect ( "{$connParams["host"]}:{$connParams["port"]}" , $connParams["dbAdmin"] , $connParams["dbAdminPwd"] ) ){
			
			@mysql_close( $conn );
		
			$result["state"] = "OK";
			
			$result["msg"] = "Connection estabilished";
			
			echo json_encode( $result );

			exit;
			
		}
		
		$result["state"] = "KO";
		
		$result["errMsg"] = mysql_error();
			
		echo json_encode( $result );
		
		exit;
	
	}
	
	function install( $params ){
		
		//Checking values		
		foreach( $params as $key => $value ){
		
			$params[$key] = trim( $value );
			
		}
		
				
		$result = array();
		
		if( !isset( $params["host"] ) or $params["host"] == "" ){
			
			$result["state"] = "KO";
			
			$result["errMsg"] = "DB host cannot be null";
			
			echo json_encode( $result );
	
			exit;
		
		}
		
		if( !isset( $params["port"] ) or $params["port"] == "" ){
			
			$result["state"] = "KO";
			
			$result["errMsg"] = "DB port cannot be null";
			
			echo json_encode( $result );
	
			exit;
		
		}
		
		if( !isset( $params["dbAdmin"] ) or $params["dbAdmin"] == "" ){
			
			$result["state"] = "KO";
			
			$result["errMsg"] = "A name for the CMS administartor must be specified";
			
			echo json_encode( $result );
	
			exit;
		
		}
		
		if( !isset( $params["dbAdminPwd"] ) or $params["dbAdminPwd"] == "" ){
			
			$result["state"] = "KO";
			
			$result["errMsg"] = "A password for the CMS administartor must be specified";
			
			echo json_encode( $result );
	
			exit;
		
		}
		
		if( !isset( $params["cmsName"] ) or $params["cmsName"] == "" ){
			
			$result["state"] = "KO";
			
			$result["errMsg"] = "A name for the platform must be specified";
			
			echo json_encode( $result );
	
			exit;
		
		}
		
		if( !isset( $params["cmsAdmin"] ) or $params["cmsAdmin"] == "" ){
			
			$result["state"] = "KO";
			
			$result["errMsg"] = "A name for the CMS admin account must be specified";
			
			echo json_encode( $result );
	
			exit;
		
		}
		
		if( !isset( $params["cmsAdminPwd"] ) or $params["cmsAdminPwd"] == "" ){
			
			$result["state"] = "KO";
			
			$result["errMsg"] = "A password for the CMS admin account must be specified";
			
			echo json_encode( $result );
	
			exit;
		
		}
		
		if( $params["cmsAdminPwd"] != $params["cmsAdminPwdRepeat"] ){
			
			$result["state"] = "KO";
			
			$result["errMsg"] = "The two inserted passwords don't match";
			
			echo json_encode( $result );
	
			exit;
		
		}
		
		if( !isset( $params["cmsAdminEmail"] ) or $params["cmsAdminEmail"] == "" ){
			
			$result["state"] = "KO";
			
			$result["errMsg"] = "An email for the CMS admin account must be specified";
			
			echo json_encode( $result );
	
			exit;
		
		}
		
		if( !preg_match( "/^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$/" , $params["cmsAdminEmail"] ) ){
			
			$result["state"] = "KO";
			
			$result["errMsg"] = "The email address is not valid";
			
			echo json_encode( $result );
	
			exit;
						
		}
		
		if( $params["cmsAdminEmail"] != $params["cmsAdminEmailRepeat"] ){
			
			$result["state"] = "KO";
			
			$result["errMsg"] = "The two inserted email don't match";
			
			echo json_encode( $result );
	
			exit;
		
		}
		
		//Testing connection	
		if( !( $conn = @mysql_connect ( "{$params["host"]}:{$params["port"]}" , $params["dbAdmin"] , $params["dbAdminPwd"] ) ) ){

			$result["state"] = "KO";
			
			$result["errMsg"] = mysql_error();
			
			echo json_encode( $result );
	
			exit;
		
		}
		
		//Create database
		
		$query_create_database =" CREATE DATABASE {$params["cmsName"]}";	
		
		$res = mysql_query( $query_create_database );
		
		if( $res === false ){
			
			$result["state"] = "KO";
			
			$result["errMsg"] = mysql_error();
			
			@mysql_close( $conn );
		
			echo json_encode( $result );
	
			exit;
			
		}
		
		
		//Use database		
		if (!mysql_select_db( $params["cmsName"] ) ){
			
			$result["state"] = "KO";
			
			$result["errMsg"] = mysql_error();
			
			@mysql_close( $conn );
		
			echo json_encode( $result );
	
			exit;			
		}
		
				
		//Create user_permissions table
		$query_create_user_permissions_table = "CREATE TABLE ".CONST_USER_PERMISSIONS_TABLE." (
		                                       
													id INT(6) NOT NULL AUTO_INCREMENT PRIMARY KEY,
													
													name VARCHAR(32) NOT NULL UNIQUE,
													
													label VARCHAR(64)
															                                       
		                                       ) TYPE = innodb ";
		
		$res = mysql_query( $query_create_user_permissions_table );
		
		if( $res === false ){
			
			$result["state"] = "KO";
			
			$result["errMsg"] = "User permission table creation: ".mysql_error();
			
			@mysql_close( $conn );
		
			echo json_encode( $result );
	
			exit;
			
		}
		
		//Create user_groups table
		$query_create_user_groups_table = "CREATE TABLE ".CONST_USER_GROUPS_TABLE." (
		                                       
													id INT(6) NOT NULL AUTO_INCREMENT PRIMARY KEY,
													
													name VARCHAR(32) NOT NULL UNIQUE,
													
													label VARCHAR(64),
													
													user_permissions VARCHAR(128) COMMENT 'A json serialized set of user_permissions' 
													
										   ) TYPE = innodb ";
		
		$res = mysql_query( $query_create_user_groups_table );
		
		if( $res === false ){
			
			$result["state"] = "KO";
			
			$result["errMsg"] = "User groups table creation: ".mysql_error();
			
			@mysql_close( $conn );
		
			echo json_encode( $result );
	
			exit;
			
		}
		
		//Create users table
		$query_create_users_table =" CREATE TABLE ".CONST_USERS_TABLE." (
		                             
										 id INT(7) NOT NULL AUTO_INCREMENT PRIMARY KEY,
										 
										 name VARCHAR(12) NOT NULL UNIQUE,		                              
										  
										 password VARCHAR(64) NOT NULL,
										 
										 email VARCHAR(256) NOT NULL,
										  
										 confirmation_code VARCHAR(64),
										 
										 confirmed INT(1) NOT NULL,
										  
										 status INT(1) NOT NULL,
										 
									 	 user_groups VARCHAR(128) COMMENT 'A json serialized set of user_groups the users is belonging'
		                            
		                             ) TYPE = innodb ";	
		
		$res = mysql_query( $query_create_users_table );
		
		if( $res === false ){
			
			$result["state"] = "KO";
			
			$result["errMsg"] = "Users table creation: ".mysql_error();
			
			@mysql_close( $conn );
		
			echo json_encode( $result );
	
			exit;
			
		}
	
		//Create admin user	
		
		$query_create_admin_user =" INSERT INTO ".CONST_USERS_TABLE." 
									
									( id, name, password, email, confirmation_code, confirmed, status, user_groups ) 
		                            
		                            VALUES(
									 
									    0,
									 
									    '{$params["cmsAdmin"]}',
									 
									    md5('{$params["cmsAdminPwd"]}'),
									 
									    md5('{$params["cmsAdminEmail"]}'),
									 
									    NULL,
									 
									    0,
									 
									    0,
									 
									    NULL									  	
									
									) ";									
			
		$res = mysql_query( $query_create_admin_user );
		
		if( $res === false ){
			
			$result["state"] = "KO";
			
			$result["errMsg"] = "Admin user account creation: ".mysql_error();
			
			@mysql_close( $conn );
		
			echo json_encode( $result );
	
			exit;
		
		}
		
		//Create content types table
		
		$query_create_content_types_table = " CREATE TABLE ".CONST_CONTENT_TYPES_TABLE." (
		                              
												  id INT(3) NOT NULL AUTO_INCREMENT PRIMARY KEY,
												  
												  name VARCHAR(18) NOT NULL UNIQUE,
												  
												  label VARCHAR(64),   
												  
												  fields VARCHAR(512) NOT NULL COMMENT 'It is a json serialization of the type field_istance_id , field_type_id , field_repetitions_number 1 or more '                  
												
											  ) TYPE = innodb ";		
			
		$res = mysql_query( $query_create_content_types_table );
		
		if( $res === false ){
			
			$result["state"] = "KO";
			
			$result["errMsg"] = "Content types table creation: ".mysql_error();
			
			@mysql_close( $conn );
		
			echo json_encode( $result );
	
			exit;
		
		}	
		
		//Create field types table		
		$query_create_field_types_table = " CREATE TABLE ".CONST_FIELD_TYPES_TABLE." (
												
												id INT(4) NOT NULL AUTO_INCREMENT PRIMARY KEY,
												  
												name VARCHAR(18) NOT NULL UNIQUE,
												  
												label VARCHAR(64),
	
		                                    ) TYPE = innodb ";
		                                    
		$res = mysql_query( $query_create_field_types_table );
		
		if( $res === false ){
			
			$result["state"] = "KO";
			
			$result["errMsg"] = "Field types table creation: ".mysql_error();
			
			@mysql_close( $conn );
		
			echo json_encode( $result );
	
			exit;
		
		}
		
		//Create platform admin DBMS user
		$query_create_admin_dbms_user = " CREATE USER '{$params["cmsAdmin"]}'@'{$params["host"]}:{$params["port"]}' IDENTIFIED BY '{$params["cmsAdminPwd"]}' ";
		
		$res = mysql_query( $query_create_admin_dbms_user );
		
		if( $res === false ){
			
			$result["state"] = "KO";
			
			$result["errMsg"] = "Plafrom admin DBMS user creation: ".mysql_error();
			
			@mysql_close( $conn );
		
			echo json_encode( $result );
	
			exit;
		
		}
		
		//Grant platform admin DBMS user
		$query_grant_admin_dbs_user = " GRANT ALL ON {$params["cmsName"]} TO '{$params["cmsAdmin"]}'@'{$params["host"]}:{$params["port"]}' ";
		
		$res = mysql_query( $query_grant_admin_dbs_user );
		
		if( $res === false ){
			
			$result["state"] = "KO";
			
			$result["errMsg"] = "Plafrom admin DBMS user privileges grant: ".mysql_error();
			
			@mysql_close( $conn );
		
			echo json_encode( $result );
	
			exit;
		
		}	
		
		//Connection string to be hardcoded into the common\config.include ,placeholder: cmsDBConn
		$CMSConnectionString = '@mysql_connect ( "'.$params["host"].':'.$params["port"].'" , "'.$params["cmsAdmin"].'" , "'.$params["cmsAdminPwd"].'" )';
		
		if ( !replaceConfigPlaceHolder( $CMSConnectionString , "cmsDBConn" ) ){
			
			$result["state"] = "KO";
			
			$result["errMsg"] = "An error occurred while setting the connection string for the platform";
		
			echo json_encode( $result );
	
			exit;
			
		}
		
		if ( !replaceConfigPlaceHolder( $params["cmsName"] , "portalName" ) ){
			
			$result["state"] = "KO";
			
			$result["errMsg"] = "An error occurred while setting the name of the platform";
		
			echo json_encode( $result );
	
			exit;
			
		}
		
		if ( !replaceConfigPlaceHolder( dirname(__FILE__) , "portalRootFolder" ) ){
			
			$result["state"] = "KO";
			
			$result["errMsg"] = "An error occurred while setting the root folder of the platform";
		
			echo json_encode( $result );
	
			exit;
			
		}
		
		if ( !replaceConfigPlaceHolder( "YES" , "isInstalled" ) ){
			
			$result["state"] = "KO";
			
			$result["errMsg"] = "An error occurred while setting the activation status of the platform";
		
			echo json_encode( $result );
	
			exit;
			
		}
		
		
		
		//OK cms correctly installed
		//Send an email to the user specifed as admin
		$emailBody = "";
		
		if( !( $mailed = @mail( $params["cmsAdminEmail"] , "Platform {$params["cmsName"]} installation" , $emailBody ) ) ){
			
			$result["msg"] = "An error occurred while sending an email to the address associated to the platform admin: {$params["cmsAdminEmail"]}";
			
		}
		else{
		
			$result["msg"] = "A message has been sent to the address associated to the platform admin: {$params["cmsAdminEmail"]}";
			
		}

		
		$result["state"] = "OK";
			
		$result["msg"] .= "CMS succesfully installed";
		
		@mysql_close( $conn );
	
		echo json_encode( $result );

		exit;
	
	}
	
	//Replaces the given placeholder with the given value into the platform configuration file	
	//TODO mettere dei controlli sull'effettiva apertura del file
	//TODO mettere dei controlli sull'effettiva sostituzione del file
	//TODO sostituire con la funzione in common/function.php
	function replaceConfigPlaceHolder( $content, $placeHolder ){
	
		$res = false;
	
		$str = implode( "\n" ,file( CONST_CONFIG_FILE ) );
		
		$str = str_replace( "//[start]<{$placeHolder}>[end]//" , $content , $str );
		
		$fh = fopen ( CONST_CONFIG_FILE , 'w' );
		
		fwrite( $fh , $str , strlen( $str ) );
		
		fclose( $fh );
		
		$res = true;
		
		return $res;
		
	}
	
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">

	<head>
	
	<meta http-equiv="content-type" content="text/html;charset=utf-8" />
	
	<title>CMS Installation</title>
	
	<script language="text/javascript" src="../lib/js/common.js"></script>
	
	<script launguage="text/javascript">
	
	// <![CDATA[
	
		function testConnection( callorback, params ){
			
			if( callorback == "call" ){
			
				var opcode = <?php echo CONST_TEST_CONNECTION_OPCODE; ?>;
			
				var host = document.getElementById( "fieldDbHost" ).value;
				
				var port = document.getElementById( "fieldDbPort" ).value;
				
				var dbAdmin =  document.getElementById( "fieldDbAdmin" ).value;
				
				var dbAdminPwd =  document.getElementById( "fieldDbAdminPwd" ).value;
				
				var requestVars = new Array();
				
				requestVars["opcode"] = opcode;
				
				requestVars["params"] = new Array();
				
				requestVars["params"]["host"] = host;
				
				requestVars["params"]["port"] = port;
				
				requestVars["params"]["dbAdmin"] = dbAdmin;
				
				requestVars["params"]["dbAdminPwd"] = dbAdminPwd;	
				
				document.getElementById("testConnectionResult").innerHTML = "Testing db connection...";	
				
				sendJsonRequest( "index.php", requestVars , "POST", "testConnection" );
				
			}
			else if( callorback == "back" ){
				
				if( params.state == 'OK' ){
				
					document.getElementById("testConnectionResult").innerHTML = params.msg;
													
				}
								
				else if( params.state == 'KO' ){
				
					document.getElementById("testConnectionResult").innerHTML = params.errMsg;
														
				}
				
			}
											
		}	
		
		var installationSteps = new Array();
		
		function install( callorback, params ){
			
		    if( callorback == "call" ){
				
				testConnection( "call" , null );
				
				var opcode = <?php echo CONST_INSTALL_OPCODE; ?>;
			
				var host = document.getElementById( "fieldDbHost" ).value;
				
				var port = document.getElementById( "fieldDbPort" ).value;
				
				var dbAdmin =  document.getElementById( "fieldDbAdmin" ).value;
				
				var dbAdminPwd =  document.getElementById( "fieldDbAdminPwd" ).value;
				
				var cmsName =  document.getElementById( "fieldCMSName").value;
				
				var cmsAdmin = document.getElementById( "fieldCMSAdmin" ).value;
				
				var cmsAdminPwd = document.getElementById( "fieldCMSAdminPwd" ).value;
				
				var cmsAdminPwdRepeat = document.getElementById( "fieldCMSAdminPwdRepeat" ).value;
				
				var cmsAdminEmail = document.getElementById( "fieldCMSAdminEmail" ).value;
				
				var cmsAdminEmailRepeat = document.getElementById( "fieldCMSAdminEmailRepeat" ).value;
				
				var requestVars = new Array();
				
				requestVars["opcode"] = opcode;
				
				requestVars["params"] = new Array();
				
				requestVars["params"]["host"] = host;
				
				requestVars["params"]["port"] = port;
				
				requestVars["params"]["dbAdmin"] = dbAdmin;
				
				requestVars["params"]["dbAdminPwd"] = dbAdminPwd;
				
				requestVars["params"]["cmsName"] = cmsName;	
				
				requestVars["params"]["cmsAdmin"] = cmsAdmin;
				
				requestVars["params"]["cmsAdminPwd"] = cmsAdminPwd;
				
				requestVars["params"]["cmsAdminPwdRepeat"] = cmsAdminPwdRepeat;
				
				requestVars["params"]["cmsAdminEmail"] = cmsAdminEmail;
				
				requestVars["params"]["cmsAdminEmailRepeat"] = cmsAdminEmailRepeat;
				
				document.getElementById("installationResult").innerHTML = "Installing CMS...";	
				
				sendJsonRequest( "index.php", requestVars , "POST", "install" );			
			
			}
			else if( callorback == "back"){
			
				if( params.state == 'OK' ){
				
					document.getElementById("installationResult").innerHTML = params.msg;
													
				}
								
				else if( params.state == 'KO' ){
				
					document.getElementById("installationResult").innerHTML = params.errMsg;
														
				}			
			
			}
			
		}
		
		function sendJsonRequest( url, vars, method, caller ){
			
			var json = '{"opcode":"'+vars["opcode"]+'","params":{';
			
			var paramNum = 0;
			
			for( var param in vars["params"] ){	
				
				if( paramNum > 0 ){
				
					json+=',';
				
				}			

				json+='"'+param+'":"'+vars["params"][param]+'"';
					
				paramNum++;

			}
			
			json+='}}';
			
			jsonCall = "jsonCall="+json;
			
			var http = new XMLHttpRequest();
			
			http.open( method, url, true );
			
			//Send the proper header information along with the request
			http.setRequestHeader( "Content-type" , "application/x-www-form-urlencoded" );
			
			http.setRequestHeader( "Content-length" , jsonCall.length );
			
			http.setRequestHeader( "Connection" , "close" );

			http.onreadystatechange = function() {//Call a function when the state changes.
				
				if(http.readyState == 4 && http.status == 200) {
				
					eval(caller+'( "back" , '+http.responseText+' )' );
				
				}
			}
			
			http.send( jsonCall );		
		
		}	
			
	// ]]>
	
	</script>
	
	<style type="text/css" media="screen">
	
	    html, body, div, span, table, td, tr { padding: 0px; margin: 0px; }
		
		body{ background-color: #003333; color: #000000; font-size: 1em; }
		
		#installationFieldsWrapper{ margin: 20px auto 20px auto; background-color: #000099; display: table; background: blue; color: #FFFFFF; }
		
		#installationFieldsWrapper span.windowTitle { padding-left: 2px; height: 20px; display: block; font-weight: bold; font-size: 1em; }
		
		table.installationFields{ width: 500px; border: 1px solid #ffffff; background-color: #CCCCCC; color: #000000; }

		table.installationFields td.installationFieldLabel{ font-weight: bold; font-size: 1em; } 
		
		table.installationFields td.installationField{ padding-left: 20px; width: 300px; height: 50px; }
		
		table.installationFields td.installationField .inputField{ width: 200px; }

		table.installationFields a { color: #FFFFFF; background-color: #666666; font-weight: bold; text-decoration: none; padding: 5px; border-bottom: 3px outset #FFFFFF; border-right: 2px outset #FFFFFF; }
		
		table.installationFields a.actionLink:link, table.installationFields a.actionLink:visited { }
		
		table.installationFields a.actionLink:hover, table.installationFields a.actionLink:active { margin-left: 2px; border: none; } 
		
		#testConnectionResult, #installationResult { font-size: 0.8em; }
						
	</style>
	
	</head>
	
	<body>
		   
		<div id="installationFieldsWrapper" >
			
			<span class="windowTitle">CMS Platform installation - system settings</span>
		
			<table id="installationFieldsTable" class="installationFields">
			
				<tr>
				
					<td class="installationFieldLabel"><label for="dbSoftware">DBMS software</label></td>
					
					<td class="installationField">
						
						<select name="dbSoftware" id="fieldDbSoftware" class="inputField" />
						
							<option value="0">-- Select DBMS type --</option>
						
							<option value="1">Mysql</option>
						
						</select>
					
					</td>
				
				</tr>
				
				<tr>
				
					<td class="installationFieldLabel"><label for="dbHost">DBMS host</label></td> 
					
					<td class="installationField"><input type="text" name="dbHost" id="fieldDbHost" class="inputField" value="localhost" /></td>
				
				</tr>
				
				<tr>
				
					<td class="installationFieldLabel"><label for="dbPort">DBMS port</label></td> 
					
					<td class="installationField"><input type="text" name="dbPort" id="fieldDbPort" class="inputField" value="3306" /></td>
				
				</tr>
				
				<tr>
				
					<td class="installationFieldLabel"><label for="dbAdmin">DBMS admin</label></td>
					
					<td class="installationField"><input type="text" name="dbAdmin" id="fieldDbAdmin" class="inputField" value="root" /></td>
				
				</tr>
				
				<tr>
				
					<td class="installationFieldLabel"><label for="dbAdminPwd">DMBS password</label></td> 
					
					<td class="installationField"><input type="password" name="dbAdminPwd" id="fieldDbAdminPwd" class="inputField" /></td>
				
				</tr>
				
				<tr>
				
					<td>
						
						<a href="javascript:testConnection( 'call' , null );" class="actionLink">Test connection</a>					
					
					</td>
					
					<td id="testConnectionResult" class="installationField">
														
					</td>
				
				</tr>
				
				<tr>
				
					<td class="installationFieldLabel"><label for="CMSName">Platform name</label></td>
					
					<td class="installationField">
						
						<input type="text" name="CMSName" id="fieldCMSName" class="inputField" vaue="Admin" />
					
					</td>			
				
				</tr>
				
				<tr>
				
					<td class="installationFieldLabel"><label for="CMSAdmin">CMS admin</label></td>
					
					<td class="installationField">
						
						<input type="text" name="CMSAdmin" id="fieldCMSAdmin" class="inputField" vaue="Admin" />
					
					</td>
							
				</tr>
				
				<tr>
				
					<td class="installationFieldLabel"><label for="CMSAdminPwd">CMS admin password</label></td>
					
					<td class="installationField">
						
						<input type="password" name="CMSAdminPwd" id="fieldCMSAdminPwd" class="inputField" vaue="Admin" />
					
					</td>			
				
				</tr>
				
				<tr>
				
					<td class="installationFieldLabel"><label for="CMSAdminPwdRepeat">Repeat admin password</label></td>
					
					<td class="installationField">
						
						<input type="password" name="CMSAdminPwdRepeat" id="fieldCMSAdminPwdRepeat" class="inputField" vaue="Admin" />
					
					</td>			
				
				</tr>
				
				<tr>
				
					<td class="installationFieldLabel"><label for="CMSAdminEmail">CMS admin email</label></td>
					
					<td class="installationField">
						
						<input type="text" name="CMSAdminEmail" id="fieldCMSAdminEmail" class="inputField" vaue="Admin" />
					
					</td>			
				
				</tr>
				
				<tr>
				
					<td class="installationFieldLabel"><label for="CMSAdminEmailRepeat">Repeat admin email</label></td>
					
					<td class="installationField">
						
						<input type="text" name="CMSAdminEmailRepeat" id="fieldCMSAdminEmailRepeat" class="inputField" vaue="Admin" />
					
					</td>			
				
				</tr>
				
				<tr>
				
					<td>
						
						<a href="javascript:install( 'call' , null );" class="actionLink">Install CMS</a>					
					
					</td>
					
					<td id="installationResult" class="installationField">
														
					</td>
				
				</tr>
		
			</table>
			
		</div>
		
	</body>

</html>


